package cn.aias.rbac.domain.model;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.Set;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "permissions")
public class Permission {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String permissionCode; // 权限编码（如"user:create"、"article:delete"）
    private String description;    // 权限描述（如"允许创建用户"）

    // 创建时间（仅插入时赋值）
    @CreationTimestamp
    private LocalDateTime createTime;

    // 修改时间（每次更新时自动刷新）
    @UpdateTimestamp
    private LocalDateTime updateTime;

    // 权限-角色双向多对多（反向映射Role的permissions字段）
    @ManyToMany(mappedBy = "permissions")
    private Set<Role> roles;


}
